package cn.gene.timeyan.ums.webapi.ums.controller;

import cn.gene.timeyan.common.exception.TimeyanServiceException;
import cn.gene.timeyan.common.restful.JsonResult;
import cn.gene.timeyan.pojo.ums.dto.DisturbingDTO;
import cn.gene.timeyan.pojo.ums.dto.UserBindDTO;
import cn.gene.timeyan.ums.service.ISetService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用户设置    前端控制器*
 *
 * @author LWG
 * @date 2022/7/23 10:57
 * @since 1.0.0@gene.cn
 */
@RestController
@RequestMapping("/ums/Set")
@Api(tags="用户设置模块")
public class SetController {
    @Autowired
    private ISetService isetService;

    /**
     * 邮箱发送验证码
     * @param userBindDTO
     * @return
     */
    @PostMapping("/bind/send_code/email")
    @ApiOperation("邮箱发送验证码")
    public JsonResult<Void> sendVerifyCodeEmail(UserBindDTO userBindDTO){
        isetService.verifyEmail(userBindDTO);
        System.out.println(userBindDTO);
        return JsonResult.ok();
    }
    /**
     * 手机发送验证码
     * @param userBindDTO
     * @return
     */
    @PostMapping("/bind/send_code/phone")
    @ApiOperation("手机发送验证码")
    public JsonResult<Void> sendVerifyCodePhone(UserBindDTO userBindDTO){
        isetService.verifyPhone(userBindDTO);
        System.out.println(userBindDTO);
        return JsonResult.ok();
    }
    @PostMapping("/bind/email")
    @ApiOperation("绑定邮箱")
    public JsonResult<Void> bindEmail(UserBindDTO userBindDTO){
        try {
            isetService.bindEmail(userBindDTO);
        }catch (TimeyanServiceException e){
            return JsonResult.failed(e.getResponseCode(),e.getMessage());
        }
        System.out.println(userBindDTO);
        return JsonResult.ok();
    }
    @PostMapping("/bind/phone")
    @ApiOperation("手机绑定")
    public JsonResult<Void> verifyPhone(UserBindDTO userBindDTO){
        try {
            isetService.bindPhone(userBindDTO);
        }catch (TimeyanServiceException e){
            return JsonResult.failed(e.getResponseCode(),e.getMessage());
        }
        System.out.println(userBindDTO);
        return JsonResult.ok();
    }

    @PostMapping("/disturbing")
    @ApiOperation("消息免打扰")
    public JsonResult<Void> Disturbing(DisturbingDTO disturbingDTO){
        isetService.changeState(disturbingDTO);
        return JsonResult.ok();
    }
}
